<?php

namespace App\Enums;

use App\Traits\EnumTrait;

class  OrderScenesEnum
{

    use EnumTrait;

    const TECHNOLOGY = ['scene' => 100, 'code' => "TECHNOLOGY", 'text' => '技能购买', 'businessType' => 1];
    const GOODS_SELL = ['scene' => 200, 'code' => "GOODS_SELL_ORIGINAL", 'text' => '宝物出售原创', 'businessType' => 2];
    const GOODS_SELL_UNUSED = ['scene' => 201, 'code' => "GOODS_SELL_UNUSED", 'text' => '宝物出售闲置', 'businessType' => 2];
    const GOODS_GIFT = ['scene' => 202, 'code' => "GOODS_GIFT", 'text' => '宝物赠送', 'businessType' => 2];
    const GOODS_RENT = ['scene' => 203, 'code' => "GOODS_RENT", 'text' => '宝物共享', 'businessType' => 2];
    const VIP_PURCHASE = ['scene' => 300, 'code' => "VIP_PURCHASE", 'text' => '会员购买', 'businessType' => 3];


    public static function getEnumByScene($scene): ?array
    {
        foreach (self::getConstants() as $item) {
            if ($scene == $item['scene']) {
                return $item;
            }
        }
        return null;
    }

    public static function getAllByScene(): array
    {
        return array_column(self::getConstants(), "text", 'scene');
    }

    public static function getScene($enum)
    {
        return $enum['scene'];
    }

    public static function getTextByScene($scene)
    {
        foreach (self::getConstants() as $item) {
            if ($scene == $item['scene']) {
                return $item['text'];
            }
        }
        return null;
    }

    public static function getBusinessTypeByScene($scene)
    {
        foreach (self::getConstants() as $item) {
            if ($scene == $item['scene']) {
                return $item['businessType'];
            }
        }
        return null;
    }
}
